package com.own.component.common.mvc;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * CustomLongMvcConfig
 *
 * @author chenxueli
 * @date 2022-10-22 10:25:53
 */
@SpringBootConfiguration
public class CustomLongMvcConfig implements WebMvcConfigurer {

    @Override
    public void extendMessageConverters(@NotNull List<HttpMessageConverter<?>> converters) {
        // 创建自己的映射消息转换器 jackson 转化JavaBean成json字符串的转换器对象
        var converter = new MappingJackson2HttpMessageConverter();
        // 把我们定义好的映射规则对象，丢到上面的转换器里面
        converter.setObjectMapper(new JacksonObjectMapper());
        // 添加到第二个（这个东西会影响返回值）
        converters.add(1, converter);
    }

}
